package com.puppy.service.impl;

import com.puppy.mapper.DeptMapper;
import com.puppy.pojo.Dept;
import com.puppy.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service //控制反转，将创建对象的功能给到外部容器IOC
public class DeptServiceImpl implements DeptService {

    @Autowired
    private  DeptMapper deptMapper;
    @Override
    public List<Dept> findAll() {
        System.out.println("全部部门");
        return deptMapper.findAll();
    }

    @Override
    public void deleteById(Integer id) {
        System.out.println("删除部门--id:"+id);
        deptMapper.deleteById(id);
    }

    @Override
    public void addByName(Dept dept) {
        //1.补全基础属性-createTime,updateTime
        dept.setCreateTime(LocalDateTime.now());
        dept.setUpdateTime(LocalDateTime.now());
        //2.调用mapper完成添加
        deptMapper.addByName(dept);
    }

    @Override
    public Dept getById(Integer id) {
        return deptMapper.getByID(id);
    }

    @Override
    public void updateById(Dept dept) {
        //1.补全基础属性-updateTime
        dept.setUpdateTime(LocalDateTime.now());
        deptMapper.updateById(dept);
    }
}
